<template>
    <div class="app-container">
        <el-row :gutter="20">
            <el-col :span="4" :xs="24">
                <el-row ref="hMain">
                    <el-col :span="24">
                        <div class="head-container">
                            <el-input v-model="deptName" placeholder="请输入名称" clearable prefix-icon="el-icon-search"
                                style="margin-bottom: 20px" />
                        </div>
                        <el-row :gutter="10" class="mb8">
                            <el-col :span="1.5">
                                <el-button type="primary" plain icon="el-icon-plus" @click="treeHandleAdd"
                                    size="small">新增</el-button>
                            </el-col>
                            <el-col :span="1.5">
                                <el-button type="success" plain icon="el-icon-edit" @click="treehandleUpdate"
                                    size="small">修改</el-button>
                            </el-col>
                            <el-col :span="1.5">
                                <el-button type="danger" plain icon="el-icon-delete" @click="handleTreeDelete"
                                    size="small">删除</el-button>
                            </el-col>
                        </el-row>

                    </el-col>
                </el-row>

                <div class="head-container" :style="{ height: treeHeight + 'px' }" style="overflow: auto">
                    <el-tree :data="deptOptions" :props="defaultProps" :expand-on-click-node="false"
                        :filter-node-method="filterNode" :default-expanded-keys="expandedkeys"
                        :current-node-key="currentNodekey" ref="tree" node-key="id" default-expand-all highlight-current
                        @node-click="handleNodeClick" :style="isSize">
                        <template slot-scope="{ node, data }">
                            <span class="span-ellipsis" :title="node.label">{{ node.label }}</span>
                        </template>
                    </el-tree>

                </div>
            </el-col>
            <el-col :span="20" :xs="24" v-if="isfondsCode">
                <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
                    <el-form-item label="类型">
                        <el-select v-model="queryParams.type" placeholder="请选择类型" @change="handleSelectTYPE">
                            <el-option v-for="(dict, index) in deptOptionsRowType" :key="index" :label="dict.label"
                                :value="dict.value" />
                        </el-select>
                    </el-form-item>
                    <el-form-item label="显示名称" prop="fieldCaption">
                        <el-input v-model="queryParams.fieldCaption" placeholder="请输入显示名称" clearable
                            @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <el-form-item label="字段名称" prop="fieldName">
                        <el-input v-model="queryParams.fieldName" placeholder="请输入字段名称" clearable style="width: 240px" @input="toUpperCase"
                            @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <el-form-item label="元数据" prop="isMetadata">
                        <el-select v-model="queryParams.isMetadata" placeholder="元数据" clearable>
                            <el-option label="是" value="1" />
                            <el-option label="否" value="0" />
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
                    </el-form-item>
                </el-form>
                <el-row :gutter="10" class="mb8" ref="refbut">
                    <el-col :span="1.5">
                        <!-- v-hasPermi="['tenantManage:templateManage:metadata:add']" -->
                        <el-button type="primary" plain icon="el-icon-plus" @click="handleAdd"
                            :disabled="isUse == '1' ? true : false">添加</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <!-- v-hasPermi="['tenantManage:templateManage:metadata:delete']" -->
                        <el-button type="danger" plain icon="el-icon-delete" @click="handleDelete"
                            :disabled="isUse == '1' ? true : false">删除</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <!-- v-hasPermi="['tenantManage:templateManage:metadata:import']" -->
                        <el-button type="info" plain icon="el-icon-upload2" @click="handleImport"
                            :disabled="isUse == '1' ? true : false">导入</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <!-- v-hasPermi="['tenantManage:templateManage:metadata:export']" -->
                        <el-button type="warning" plain icon="el-icon-download" @click="handleExport"
                            :disabled="isUse == '1' ? true : false">导出</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <!-- v-hasPermi="['tenantManage:templateManage:metadata:bulkOperation']" -->
                        <el-dropdown :hide-on-click="false" @visible-change="dropDownShowChange($event)">
                            <el-button plain icon="el-icon-tickets" :disabled="isUse == '1' ? true : false">
                                批量操作
                            </el-button>
                            <el-dropdown-menu slot="dropdown" class="ticketsform" >
                                <el-dropdown-item><label>是否可录入：</label><el-switch v-model="ticketsform.isInput"
                                        @change="chanageFieldCaptionTap('isInput')" active-value="1"
                                        inactive-value="0" :disabled="isUse == '1' ? true : false"></el-switch></el-dropdown-item>
                                <el-dropdown-item><label>是否可修改：</label><el-switch v-model="ticketsform.isUpdate"
                                        @change="chanageFieldCaptionTap('isUpdate')" active-value="1"
                                        inactive-value="0" :disabled="isUse == '1' ? true : false"></el-switch></el-dropdown-item>
                                <!-- <el-dropdown-item><label>是否查询字段：</label><el-switch
                                        v-model="ticketsform.isInput"></el-switch></el-dropdown-item> -->
                                <el-dropdown-item><label>是否档号字段：</label><el-switch v-model="ticketsform.isArchiveNo"
                                        @change="chanageFieldCaptionTap('isArchiveNo')" active-value="1"
                                        inactive-value="0" :disabled="isUse == '1' ? true : false"></el-switch></el-dropdown-item>
                                <el-dropdown-item><label>是否非空：</label><el-switch v-model="ticketsform.isNoEmpty"
                                        @change="chanageFieldCaptionTap('isNoEmpty')" active-value="1"
                                        inactive-value="0" :disabled="isUse == '1' ? true : false"></el-switch></el-dropdown-item>
                                <el-dropdown-item><label>是否隐藏：</label><el-switch v-model="ticketsform.isHidden"
                                        @change="chanageFieldCaptionTap('isHidden')" active-value="1"
                                        inactive-value="0" :disabled="isUse == '1' ? true : false"></el-switch></el-dropdown-item>
                                <el-dropdown-item><label>是否可导出：</label><el-switch v-model="ticketsform.isExport"
                                        @change="chanageFieldCaptionTap('isExport')" active-value="1"
                                        inactive-value="0" :disabled="isUse == '1' ? true : false"></el-switch></el-dropdown-item>
                                <el-dropdown-item><label>元数据：</label><el-switch v-model="ticketsform.isMetadata"
                                        @change="chanageFieldCaptionTap('isMetadata')" active-value="1"
                                        inactive-value="0" :disabled="isUse == '1' ? true : false"></el-switch></el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </el-col>
                    <el-col :span="1.5">
                        <!-- v-hasPermi="['tenantManage:templateManage:metadata:copy']" -->
                        <el-dropdown @command="handleCommand">
                            <el-button plain icon="el-icon-document-copy" >
                                复制到
                            </el-button>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item v-for="item in deptOptionsChildrenList" :key="item.id"
                                    :command="item.id">{{ item.label }}</el-dropdown-item>

                            </el-dropdown-menu>
                        </el-dropdown>
                    </el-col>
                    <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
                </el-row>
                <metadata :list="list" :tableHeight="tableHeight" :loading="loading"
                    @handleSelectionChange="handleSelectionChange" @chanageFieldCaptionTap="getList" :isUse="isUse"
                    :isType="1" :fieldlevel="queryParams.type"></metadata>
                <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize" @pagination="getList" />
            </el-col>
        </el-row>




        <!-- 元数据方案树的添加或修改用户配置对话框 -->
        <el-dialog :title="treeTitle" :visible.sync="treeOpen" width="35%" append-to-body>
            <el-form ref="treeForm" :model="treeForm" :rules="treeRules" label-width="80px">
                <el-form-item label="名称" prop="name">
                    <el-input v-model="treeForm.name" placeholder="请输入名称" maxlength="30" />
                </el-form-item>

                <el-form-item label="描述" prop="description">
                    <el-input type="textarea" :rows="2" v-model="treeForm.description" placeholder="请输入描述" maxlength="30" />
                </el-form-item>
                <el-form-item label="整理方式" prop="type">
                    <el-select v-model="treeForm.type" placeholder="请选择整理方式" class="el-selectTree" :disabled="isDisabled">
                        <el-option v-for="item in collatedForms" :key="item.value" :label="item.label"
                            :value="item.value"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="排序" prop="orderNo">
                    <el-input-number style="width:300px" v-model="treeForm.orderNo" controls-position="right"
                        placeholder="请输入排序" :min="1" :max="500"></el-input-number>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitTrreForm">确 定</el-button>
                <el-button @click="treeCancel">取 消</el-button>
            </div>
        </el-dialog>



        <!-- 元数据方案添加对话框 -->
        <mdataAdd v-if="open == true" ref="dialogRef" :cateMdataOpen="open" @closeMdataDelDialog="closeMdataDelDialog"
            :addParams="addParams" @addSubmitTap="addSubmitTap"></mdataAdd>
        <!-- {{ queryParams }} -->
        <!-- 用户导入对话框 -->
        <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
            <el-upload ref="upload" :on-change="handleFileChange" :file-list="fileList" accept=".xlsx, .xls" :headers="upload.headers"
                :action="upload.url + '?groupId=' + queryParams.groupId + '&type=1'" :disabled="upload.isUploading"
                :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
                <i class="el-icon-upload"></i>
                <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                <div class="el-upload__tip text-center" slot="tip">
                    <!--                    <div class="el-upload__tip" slot="tip">-->
                    <!--                        <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的基础数据-->
                    <!--                    </div>-->
                    <span>仅允许导入xls、xlsx格式文件。</span>
                    <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
                        @click="importTemplate">下载模板</el-link>
                </div>
            </el-upload>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitFileForm">确 定</el-button>
                <el-button @click="upload.open = false">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>

import {
  listGROUPTree,
  delGroupTree,
  getGroupTree,
  addGroupTree,
  updateGroupTree,
  mdataList,
  addMdataDatalist,
  delmdataList,
  addMdataList,
  updateMdataarchive,
  copyIsRepeat,
  copyToGroup,
  copyGroupList, updateMdataarchiveBatch
} from "@/api/archive/metaData.js";
import estimateTableHeight from '@/mixins/estimateTableHeight'//vue项目中element-tabel自动计算高度
import metadata from "@/components/mdataList/index.vue"
import mdataAdd from "@/components/mdataList/mdataAdd.vue"//元数据明细信息列表添加
import { getToken } from "@/utils/auth";
export default {
    dicts: ['sys_normal_disable', 'basic_data_fieldtype'],
    mixins: [estimateTableHeight], // 混入方法
    components: {
        metadata,
        mdataAdd
    },
    data() {

        return {
            rowData: "",//当前点击树信息
            isUse: "",
            // 选中数组
            ids: [],
            label: [],
            //添加列表的选中数组
            addIds: [],
            //元数据方案树是否显示弹出层
            treeOpen: false,
            addParams: "",
            //元数据方案是否显示弹出层
            open: false,
            //元数据方案树弹出层(标题)
            treeTitle: "",
            //元数据方案弹出层（标题）
            title: "",
            //元数据方案整理方式：添加可以编辑，修改时禁止编辑
            isDisabled: false,
            // 遮罩层
            loading: true,
            addloading: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            //添加的列表数据  总条数
            addTotal: 0,
            // 用户表格数据
            list: null,
            addList: null,
            // 元数据方案树选项
            deptOptions: undefined,
            //元数据方案复制到列表
            deptOptionsChildrenList: undefined,
            //获取当前点击的元数据方案树
            deptOptionsRow: undefined,
            //更具当前点击的元数据方案树 显示元数据明细查询类型
            deptOptionsRowType: undefined,
            //默认展开的树节点
            expandedkeys: [],
            //默认选中的树节点
            currentNodekey: "",
            // 部门名称
            deptName: undefined,
            defaultProps: {
                children: "children",
                label: "label"
            },
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                groupId: undefined,
                fieldCaption: undefined,
                fieldName: undefined,
                type: undefined,
                isMetadata: undefined
            },

            //添加到数据明细基础列表
            queryAddParams: {
                pageNum: 1,
                pageSize: 10,
                groupId: undefined,
                fieldCaption: "",
                fieldName: "",
                type: undefined,
            },

            //批量操作
            ticketsform: {
                isInput: undefined, //是否可录入0=否,1=是
                isUpdate: undefined, //是否可修改0=否,1=是
                isArchiveNo: undefined, //是否档号字段0=否,1=是
                isNoEmpty: undefined, //是否非空0=否,1=是
                isHidden: undefined, //是否隐藏0=否,1=是
                isExport: undefined, //是否可导出0=否,1=是
                isMetadata: undefined, //是否元数据0=否,1=是
            },
            //树表单参数
            treeForm: {},
            //树表单校验
            treeRules: {
                name: [
                    { required: true, message: '请输入元数据方案名称', trigger: 'blur' },
                ],
                type: [
                  { required: true, message: '请输入整理方式' },
                ]
            },

            //元数据方案树添加---整理方式下拉列表
            collatedForms: [
                {
                    value: '0',
                    label: '组件'
                }, {
                    value: '1',
                    label: '组卷'
                }, {
                    value: '3',
                    label: '项目类型'
                },
            ],
            //类型
            fileorupTypeOption: [],
            // 用户导入参数
            upload: {
                // 是否显示弹出层（用户导入）
                open: false,
                // 弹出层标题（用户导入）
                title: "",
                // 是否禁用上传
                isUploading: false,
                // 是否更新已经存在的基础数据
                updateSupport: 0,
                // 设置上传的请求头部
                headers: { Authorization: "Bearer " + getToken() },
                // 上传的地址
                url: process.env.VUE_APP_BASE_API + "/archive/mdataList/importData"
            },
            isfondsCode: true,
            fileList: []
        }
    },
    watch: {
        // 根据名称筛选部门树
        deptName(val) {
            this.$refs.tree.filter(val);
        },
    },
    created() {
        this.getDeptTree();
    },
    mounted() {

        window['layerTest'] = () => {

            this.fetchData();

        }

    },
    computed: {

        isSize() {

            if (this.$store.getters.size == 'small') {
                this.size = 'font-size: 12px;'
            } else {
                this.size = 'font-size: 14px;'
            }
            return this.size
        }


    },
    methods: {
        toUpperCase() {
          this.queryParams.fieldName = this.queryParams.fieldName.toUpperCase()
        },
        /**元数据明细列表 */
        getList() {
            this.loading = true;
            console.log(this.queryParams)
            mdataList(this.queryParams).then(response => {
                this.list = response.rows;
                this.total = response.total;
                this.loading = false;
            }
            );
        },

        //展示可以添加到元数据明细的基础数据列表
        getAddList() {
            addMdataDatalist(this.queryAddParams).then(response => {
                this.addList = response.rows;
                this.addTotal = response.total;
                this.addloading = false;
            }
            );
        },
        deptOptionsSelect(type) {
            if (type == 0) {
                this.deptOptionsRowType = [
                    { value: '0', label: '件层' },
                    { value: '2', label: '电子文件层' },
                ]
            } else if (type == 1) {
                this.deptOptionsRowType = [
                    { value: '1', label: '卷层' },
                    { value: '0', label: '件层' },
                    { value: '2', label: '电子文件层' },
                ]
            } else {
                this.deptOptionsRowType = [
                    { value: '3', label: '项目层' },
                    { value: '1', label: '卷层' },
                    { value: '0', label: '件层' },
                    { value: '2', label: '电子文件层' },

                ]
            }
        },
        // 多选框选中数据
        handleSelectionChange(ids, selection) {
            this.ids = ids;
            this.label = selection.map(item => item.fieldCaption)
        },
        // 添加多选框选中数据
        addSelectionChange(selection) {
            this.addIds = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 查询部门下拉树结构 */
        getDeptTree() {
            listGROUPTree().then(response => {
                this.deptOptions = response.data;
                if (this.deptOptions.length > 0) {
                    console.log(this.deptOptions[0].children[0])
                    this.currentNodeKey = this.deptOptions[0].children[0].id;
                    this.isUse = this.deptOptions[0].children[0].isUse;  //元数据方案已被使用过isUse!==1,禁用所有按钮不能再点击
                    this.deptOptionsSelect(this.deptOptions[0].children[0].type);
                    this.expandedkeys.push(this.deptOptions[0].children[0].id);
                    this.deptOptionsRow = this.deptOptions[0].children[0]
                    this.$nextTick(() => {
                        this.$refs.tree.setCurrentKey(this.deptOptions[0].children[0].id)
                    })
                    this.queryParams.groupId = response.data[0].children[0].id;

                    // this.deptOptionsChildrenList = response.data[0].children.filter((item) => {
                    //     return item.id != response.data[0].children[0].id
                    // })

                    this.queryParams.type = response.data[0].children[0].type.toString();
                    this.getGroupList()
                    this.getList();
                }
            });
        },
        // 筛选节点
        filterNode(value, data) {
            if (!value) return true;
            return data.label.indexOf(value) !== -1;
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },

        //搜素添加列表操作
        addHandleQuery() {
            this.queryAddParams.pageNum = 1;
            this.getAddList();
        },

        //类型下拉
        handleSelectTYPE() {
           this.queryParams.pageNum = 1;
           this.queryParams.pageSize = 10;
            this.getList();
        },
        // 表单重置
        reset() {
            this.treeForm = {
                name: null,
                description: null,
                type: null,
                orderNo: null,
                id: null
            }
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            if (this.rowData.length == undefined) {
                this.queryParams.type = this.rowData.type.toString();
            } else {
                this.queryParams.type = this.deptOptions[0].children[0].type.toString();
            }
            this.getList();
        },
        addResetQuery() {
            this.resetForm("queryAddForm");
            this.getAddList();
        },

        // 节点单击事件
        handleNodeClick(data) {
            if (data.id == '0') {
                this.isfondsCode = false
            } else {
                this.isfondsCode = true
                this.rowData = data;
                // 点击树节点时刷新查询条件
                this.resetForm("queryForm");
                this.queryParams.groupId = data.id;
                this.queryParams.type = data.type.toString();
                this.deptOptionsRow = data;
                this.isUse = data.isUse;
                this.deptOptionsSelect(data.type);
                //复制到
                // this.deptOptionsChildrenList = this.deptOptions[0].children.filter((item) => {
                //     return item.id != data.id
                // })
                this.getGroupList()
                this.getList();
                this.loading = false;
                this.addloading = false;
            }
        },

        //元数据方案树添加、修改
        treeHandleAdd() {
            var that = this;
            that.treeOpen = true;
            that.treeTitle = "添加元数据方案 ";
            this.isDisabled = false
            this.resetForm('treeForm')
            this.reset();
        },
        //元数据方案树修改
        treehandleUpdate() {
            this.reset();
            this.resetForm('treeForm')
            getGroupTree(this.queryParams.groupId).then(response => {
                this.treeForm = response.data;
                this.treeForm.type = response.data.type.toString()
                this.treeOpen = true;
                this.isDisabled = true
                this.treeTitle = "修改元数据方案 ";
            });
        },

        //元数据方案树添加提交
        submitTrreForm() {
            console.log(this.treeForm, "lsdkfjkl")
            this.$refs["treeForm"].validate((valid) => {
                if (valid) {
                    if (this.treeForm.id != null) {
                        updateGroupTree(this.treeForm).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.treeOpen = false;
                            this.getDeptTree();
                        });
                    } else {
                        addGroupTree(this.treeForm).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.treeOpen = false;
                            this.getDeptTree();
                        });
                    }
                }
            })
        },
        //元数据方案树修改取消
        treeCancel() {
            var that = this;
            that.treeOpen = false;
        },

        //元数据明细添加操作
        handleAdd() {
            var that = this;
            that.open = true;
            this.addParams = {
                cateIsType: "1",
                queryAddParams: {
                    groupId: this.deptOptionsRow.id,
                    type: this.queryParams.type,
                    pageNum: 1,
                    pageSize: 10,
                    categoryId: ""
                }
            }
        },

        //元数据信息明细添加页面关闭
        closeMdataDelDialog() {
            var that = this;
            that.open = false;
        },
        //元数据信息明细添加页面成功关闭
        addSubmitTap(){
            var that = this;
            that.open = false;
            that.getList();
        },

        //元数据方案树 删除
        handleTreeDelete() {
            if (this.isUse == 1) {
                this.$modal.msgWarning('该元数据方案已被使用,不能进行删除操作')
                return
            }
            var row = this.deptOptions[0].children.filter((item) => {
                return item.id == this.queryParams.groupId
            })

            this.$modal.confirm('是否确认删除元数据方案名称为"' + row[0].label + '"的数据项？').then(function () {

                return delGroupTree(row[0].id);

            }).then(() => {
                this.getDeptTree();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },

        //删除元数据明细
        handleDelete(row) {
            const ids = row.id || this.ids;
            const label = row.fieldCaption || this.label
            console.log(ids)
            if (ids.length !== 0) {
                this.$modal.confirm('是否确认删除显示名称为"' + label + '"的数据项？').then(function () {
                    return delmdataList(ids);
                }).then(() => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                }).catch(() => { });
            } else {
                this.$modal.msgError("请选择要删除的数据");
            }
        },


        //修改元数据明细
        chanageFieldCaptionTap(val) {
            var data = "";

            if (this.ids.length !== 0) {

                for(var i in  Object.keys(this.ticketsform)){
                    if(Object.keys(this.ticketsform)[i]!=val){
                        this.ticketsform[Object.keys(this.ticketsform)[i]]=undefined
                    }

                }
                this.ticketsform["ids"]=this.ids.toString();
            this.ticketsform["groupId"]=this.queryParams.groupId;
              console.log( this.ticketsform)

                updateMdataarchiveBatch(this.ticketsform).then(response => {
                    this.$modal.msgSuccess("修改成功");
                    // this.getList();
                    this.list.filter(v => this.ids.some(val => {
                        if (val === v.id) {
                            if (this.ticketsform.isInput != undefined) {
                                v.isInput = this.ticketsform.isInput
                            }
                            if (this.ticketsform.isUpdate != undefined) {
                                v.isUpdate = this.ticketsform.isUpdate
                            }
                            if (this.ticketsform.isArchiveNo != undefined) {
                                v.isArchiveNo = this.ticketsform.isArchiveNo
                            }
                            if (this.ticketsform.isNoEmpty != undefined) {
                                v.isNoEmpty = this.ticketsform.isNoEmpty
                            }
                            if (this.ticketsform.isHidden != undefined) {
                                v.isHidden = this.ticketsform.isHidden
                            }

                            if (this.ticketsform.isExport != undefined) {
                                v.isExport = this.ticketsform.isExport
                            }

                            if (this.ticketsform.isMetadata != undefined) {
                                v.isMetadata = this.ticketsform.isMetadata
                            }

                        }
                    }))
                });
            } else {
                this.$modal.msgError("请选择修改的数据")
                this.ticketsform = {
                    isInput: undefined, //是否可录入0=否,1=是
                    isUpdate: undefined, //是否可修改0=否,1=是
                    isArchiveNo: undefined, //是否档号字段0=否,1=是
                    isNoEmpty: undefined, //是否非空0=否,1=是
                    isHidden: undefined, //是否隐藏0=否,1=是
                    isExport: undefined, //是否可导出0=否,1=是
                    isMetadata: undefined, //是否元数据0=否,1=是
                }
            }

        },

        //批量操作下拉框隐藏时触发
        dropDownShowChange(event) {
            //   console.log(event,"sdkfjklsdjl")
            if (!event) {
                this.ticketsform = {
                    isInput: undefined, //是否可录入0=否,1=是
                    isUpdate: undefined, //是否可修改0=否,1=是
                    isArchiveNo: undefined, //是否档号字段0=否,1=是
                    isNoEmpty: undefined, //是否非空0=否,1=是
                    isHidden: undefined, //是否隐藏0=否,1=是
                    isExport: undefined, //是否可导出0=否,1=是
                    isMetadata: undefined, //是否元数据0=否,1=是
                }
            }
        },
        /** 导出按钮操作 */
        handleExport() {
            this.queryParams['ids']=this.ids.toString();
            this.download('/archive/mdataList/export', {
                ...this.queryParams
            }, `basicdata_${new Date().getTime()}.xlsx`)

        },

        /**导入按钮操作 */
        handleImport() {
            this.upload.title = "元数据明细导入";
            this.upload.open = true;
        },
        // 文件上传中处理
        handleFileUploadProgress(event, file, fileList) {
            this.upload.isUploading = true;
        },
        handleFileChange(file, fileList) {
          this.fileList = []
          let length = fileList.length
          this.fileList = [fileList[length - 1]]
        },
        // 文件上传成功处理
        handleFileSuccess(response, file, fileList) {
            this.upload.open = false;
            this.upload.isUploading = false;
            this.$refs.upload.clearFiles();
            this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
            this.getList();
        },
        /** 下载模板操作 */
        importTemplate() {
            this.download('/archive/mdataList/importTemplate', {
            }, `basicdata_template_${new Date().getTime()}.xlsx`)
        },
        // 提交上传文件
        submitFileForm() {
            this.$refs.upload.submit();
        },


        //复制到  点击列表事件
        handleCommand(command) {
            //  this.$message('click on item ' + command,data);
            console.log(command, this.queryParams, this.ids, "dklfjkl")
            if (this.ids.length !== 0) {
                copyIsRepeat({
                    ids: this.ids.toString(),
                    groupId: command,
                    type: this.queryParams.type
                }).then(response => {
                    if (response.msg == 200) {
                        copyToGroup({
                            ids: this.ids.toString(),
                            groupId: command,
                            type: ""
                        }).then(response => {
                            this.$modal.msgSuccess("复制成功");
                        })
                    } else {
                        this.$confirm(response.msg, {
                            confirmButtonText: '覆盖',
                            cancelButtonText: '跳过',
                            distinguishCancelAndClose: true,
                        }).then(function () {
                        }).then(() => {
                            copyToGroup({
                                ids: this.ids.toString(),
                                groupId: command,
                                type: 1
                            }).then(response => {
                                this.$modal.msgSuccess("覆盖成功");
                            })
                        }).catch((action) => {
                            if(action=="cancel"){
                                copyToGroup({
                                ids: this.ids.toString(),
                                groupId: command,
                                type: 2
                            }).then(response => {
                                this.$modal.msgSuccess("跳过成功");
                            })
                      
                            }
                        });
                            
                    }
                })
            } else {
                this.$modal.msgError("请选择要复制的数据")
            }
        },

        // 获取复制到下拉列表
        getGroupList() {
            copyGroupList(this.queryParams).then(response => {
                this.deptOptionsChildrenList = response.data.map(item => {
                    return {
                        id: item.id,
                        label: item.name
                    }
                })
            })
        }

    }
}
</script>
<style lang="less" scoped>
::v-deep.el-selectTree .el-input {
    width: 300px;
}

.span-ellipsis {
    display: block;
    // font-size: 14px;
}


::v-deep .el-dialog {
    padding: 0px 30px 20px 0px !important;
    display: flex;
    flex-direction: column;
    margin: 0 !important;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-height: calc(100% - 30px);
    max-width: calc(100% - 30px);
}

::v-deep .el-dialog .el-dialog__body {
    flex: 1;
    overflow: auto;
}

::v-deep .el-form-item__content {
    line-height: 26px;
}

.el-dropdown-menu {
  max-height: 400px; /*设置菜单高度为200px*/
  overflow-y: auto; /*设置滚动条*/
}
</style>
